import {Component, Injector, OnInit} from '@angular/core';
import {CoreComponent} from 'pengesoft-ng-lib';
import {EmployeeServiceSvr} from '../../../services/employee.service';

@Component({
  selector: 'app-roster',
  templateUrl: './roster.component.html',
  styleUrls: ['./roster.component.less']
})
export class RosterComponent extends CoreComponent implements OnInit {

  isClick1 = true;
  isClick2 = false;
  isClick3 = false;

  // 传给子组件，判断点了哪个
  checkState = '在职';
  // 传给子组件的数据
  // tslint:disable-next-line:max-line-length
  sendRosterTableData: { skay: number; jobnumber: any; phone: any; sex: string; name: any; id: any; state: any; posting: any; department: any; age: any }[] = [];


  gridStyle = {
    width: '33.3%',
    textAlign: 'center'
  };

  constructor(private injector: Injector,
              private employSvr: EmployeeServiceSvr) {
    super(injector);
  }

  ngOnInit(): void {
    this.queryEmployee();
  }

  // 是否点击了在职/试用/正式
  GridClick(i): void {
    if (i === 1) {
      this.checkState = '所有';
    }else if (i === 2) {
      this.checkState = '在职';
    }else if (i === 3) {
      this.checkState = '离职';
    }
    switch (i) {
      case 1:
        this.isClick1 = true;
        this.isClick2 = false;
        this.isClick3 = false;
        break;
      case 2:
        this.isClick2 = true;
        this.isClick1 = false;
        this.isClick3 = false;
        break;
      case 3:
        this.isClick2 = false;
        this.isClick1 = false;
        this.isClick3 = true;
        break;
    }
    // this.queryEmployee();
    i === 1 ? this.queryEmployee() : this.queryEmployeeByState(this.checkState);
  }

  // 查询所有员工花名册/档案
  queryEmployee(): any {
    this.employSvr.myGetAllEmployDto().then(res => {
      this.sendRosterTableData = this.dealData(res);
      return this.sendRosterTableData;
    });
  }

  // 按状态查员工花名册
  queryEmployeeByState( state ): any{
    this.employSvr.myGetEmployeeDtoByState( state ).then(res => {
      this.sendRosterTableData = this.dealData(res);
      return this.sendRosterTableData;
    });
  }

  // 返回数据处理
  dealData(res): any{
   return res.map((items, index) => {
      const sex = items.Employee.Sex === 0 ? '男' : '女';
      return {
        id: items.Employee.Id,
        skay: index + 1,
        posting: items.JobName,
        department: items.DeptName,
        jobnumber: items.Employee.Id,
        age: items.Employee.Age,
        sex,
        phone: items.Employee.Phone,
        state: items.Employee.StateId,
        name: items.Employee.Name,
        identifyCard: items.Employee.IDCard,
        identifyId: items.Employee.IDCard,
        school: items.Employee.GraduatedSchool,
        major: items.Employee.StudyMajor,
        degree: items.Employee.EducationLevel,
        political: items.Employee.Politic,
        native: items.Employee.NativePlace,
        emergencyPerPhone: items.Employee.EmergencyContact,
        emergencyPer: items.Employee.EmergencyPeople,
        employeeForm: items.Employee.EmployForm,
        cardNum: items.Employee.CardNum,
        IDPlace: items.Employee.IDPlace,
        NowPlace: items.Employee.NowPlace,
      };

    });
  }

}
